package com.lindroid.controller

import com.lindroid.entity.User
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.ui.ModelMap
import org.springframework.web.bind.annotation.PostMapping
import java.util.*


/**
 * @author Lin
 * @date 2019/10/27
 * @function
 * @Description
 */
@Controller //使用RestController无法解析html
@RequestMapping("th")
class ThymeleafController {
    @RequestMapping("/index")
    fun index(map: ModelMap): String {
        map.addAttribute("name", "thymeleaf-imooc")
        return "thymeleaf/index"
    }

    @RequestMapping("/center")
    fun index(): String {
        return "thymeleaf/center/center"
    }

    @RequestMapping("/test")
    fun test(map: ModelMap): String {
        val user = User(
            name="superadmin",
            age = 18,
            birthday = Date(),
            desc = "<font color='green'><b>hello<b/></font>"
        )
        map.addAttribute("user", user)

        val user1 = User(
            name="Licy",
            age = 20,
            birthday = Date()
        )

        val userList = ArrayList<User>()
        userList.add(user)
        userList.add(user1)
        map.addAttribute("userList", userList)
        return "thymeleaf/test"
    }

    @PostMapping("/postform")
    fun postForm(user: User): String {
        println(user.name)
        return "redirect:/th/test"
    }
}